package com.cmlite.model;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class OutProfile {
	/*
	 * :{"id":"1", "username":"admin", "first_name":"", "last_name":"",
	 * "full_name":"Administrator", "email":"admin@admin.com", "is_active":"1",
	 * "properties":"", "active_code":""},
	 */
	private int id;
	private String id_device;
	private String id_contact;
	private String username;
	private String first_name;
	private String last_name;
	private String full_name;
	private String email;
	private String properties;
	private int active_code;
	private String address;
	private String address_other;
	private String birthday;
	private String gender;
	private String phone;
	private String phone_other;

	public String getPhone_other() {
		return phone_other;
	}

	public void setPhone_other(String phone_other) {
		this.phone_other = phone_other;
	}

	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getBirthday() {
		return birthday;
	}

	public void setBirthday(String birthday) {
		this.birthday = birthday;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}

	public void setId(String id) {
		this.id = Integer.parseInt(id);
	}

	/**
	 * @return the username
	 */
	public String getUsername() {
		return username;
	}

	/**
	 * @param username
	 *            the username to set
	 */
	public void setUsername(String username) {
		this.username = username;
	}

	/**
	 * @return the first_name
	 */
	public String getFirst_name() {
		return first_name;
	}

	/**
	 * @param first_name
	 *            the first_name to set
	 */
	public void setFirst_name(String first_name) {
		this.first_name = first_name;
	}

	/**
	 * @return the last_name
	 */
	public String getLast_name() {
		return last_name;
	}

	/**
	 * @param last_name
	 *            the last_name to set
	 */
	public void setLast_name(String last_name) {
		this.last_name = last_name;
	}

	/**
	 * @return the full_name
	 */
	public String getFull_name() {
		return full_name;
	}

	/**
	 * @param full_name
	 *            the full_name to set
	 */
	public void setFull_name(String full_name) {
		this.full_name = full_name;
	}

	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @param email
	 *            the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @return the properties
	 */
	public String getProperties() {
		return properties;
	}

	/**
	 * @param properties
	 *            the properties to set
	 */
	public void setProperties(String properties) {
		this.properties = properties;
		try {
			JSONObject o = new JSONObject(properties);
			if (o.length() > 0) {
				this.phone = "";
				this.gender = o.isNull("gender") ? "" : o.getString("gender");
				this.birthday = o.isNull("birthday") ? "" : o
						.getString("birthday");
				this.address = o.isNull("address") ? "" : o
						.getString("address");
				this.address_other = o.isNull("work_address") ? "" : o
						.getString("work_address");
				this.phone = o.isNull("phone") ? "" : o.getString("phone");
				this.phone_other = o.isNull("work_phone") ? "" : o
						.getString("work_phone");
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	/**
	 * @return the active_code
	 */
	public int getActive_code() {
		return active_code;
	}

	@Override
	public String toString() {
		return "OutProfile [id=" + id + ", id_device=" + id_device
				+ ", id_contact=" + id_contact + ", username=" + username
				+ ", first_name=" + first_name + ", last_name=" + last_name
				+ ", full_name=" + full_name + ", email=" + email
				+ ", properties=" + properties + ", active_code=" + active_code
				+ ", address=" + address + ", address_other=" + address_other
				+ ", birthday=" + birthday + ", gender=" + gender + ", phone="
				+ phone + ", phone_other=" + phone_other + "]";
	}

	public String getAddress_other() {
		return address_other;
	}

	public void setAddress_other(String address_other) {
		this.address_other = address_other;
	}

	/**
	 * @param active_code
	 *            the active_code to set
	 */
	public void setActive_code(int active_code) {
		this.active_code = active_code;
	}

	public void setActive_code(String active_code) {
		this.active_code = active_code.equalsIgnoreCase("") ? -1 : Integer
				.parseInt(active_code);
	}

	public String getId_device() {
		return id_device;
	}

	public void setId_device(String id_device) {
		this.id_device = id_device;
	}

	public String getId_contact() {
		return id_contact;
	}

	public void setId_contact(String id_contact) {
		this.id_contact = id_contact;
	}
}
